#ifndef DETECTORPAGE_H
#define DETECTORPAGE_H

#include <atlcrack.h>
#include "PropPage.h"
#include "DetectorPageDlg.h"
#include "ExListViewCtrl.h"
#include "WinUtil.h"

class DetectorPage : public CPropertyPage<IDD_DETECTOR_PAGE>, public PropPage
{
public:
	DetectorPage(SettingsManager *s) : PropPage(s) { 
		SetTitle(CTSTRING(SETTINGS_DETECTOR));
		ctrlList.Detach();
	};
	~DetectorPage() { 
		for (DetectorList::Iter i = detectList.begin(); i != detectList.end(); ++i)
			delete *i;
		ctrlList.Detach();
	};

	BEGIN_MSG_MAP_EX(DetectorPage)
		MESSAGE_HANDLER(WM_INITDIALOG, onInitDialog)
		COMMAND_HANDLER(IDC_CHANGE, BN_CLICKED, onChange)
		NOTIFY_HANDLER(IDC_DETECTOR_ITEMS, NM_DBLCLK, onDblClick)
	END_MSG_MAP()

	LRESULT onInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT onHelpInfo(LPNMHDR /*pnmh*/);
	LRESULT onChange(WORD wNotifyCode, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
	LRESULT onDblClick(int /*idCtrl*/, LPNMHDR /* pnmh */, BOOL& bHandled){
		return onChange(0, 0, 0, bHandled);
	}
	//End
	
	// Common PropPage interface
	PROPSHEETPAGE *getPSP() { return (PROPSHEETPAGE *)*this; }
	virtual void write();

protected:

	void insertItem(const string& a, int b, bool displayCheat){
		StringList cols;
		cols.push_back(a);
		cols.push_back(RAWSETTING(b));
		cols.push_back(WinUtil::toYesNo(displayCheat));
		ctrlList.insert(cols);
		cols.clear();
	}

	
	ExListViewCtrl ctrlList;
	//End
	static Item items[];

	void addItem(int raw, int display, const string& text){
		detectList.push_back(new DetectorList( raw, display, text));
	}
	class DetectorList {
	public:
		typedef DetectorList* Ptr;
		typedef vector<Ptr> List;
		typedef List::iterator Iter;

		DetectorList(int _raw, int _display, const string& _text) : raw(_raw), display(_display), text(_text){	}
		GETSET(int, raw, Raw);
		GETSET(int, display, Display);
		GETSET(string, text, Text);
	};
	DetectorList::List detectList;
	
};

#endif //DETECTORPAGE_H